<?php
namespace Service;

class Withdraw extends Base
{

    private $database = null;

    public function getDatabase()
    {
        if($this->database){
            return $this->database;
        }
        $this->database = $this->get(DATABASE_WITHDRAW);
        return $this->database;
    }

    public function addReturn($userId, $amount, $realAmount, $userBank)
    {
        $tax = bcsub($amount, $realAmount, 2);
        $now = getDateTime();
        $insert = [
            'dry_user' => $userId,
            'dry_type' => WITHDRAW_TYPE_BANK_CARD,
            'dry_status' => WITHDRAW_STATUS_APPLY,
            'dry_amount' => $amount,
            'dry_tax' => $tax,
            'dry_real_amount' => $realAmount,
            'dry_user_bank_raw' => $userBank,
            'dry_month' => date('Ym', $now['timestamp']),
            'dry_add_time' => $now['date_time']
        ];
        return $insert;
    }

    public function getList($userId, $page, $limit)
    {
        return $this->getDatabase()->getList($userId, $page, $limit);
    }

}